from celery_tasks.main import celery_app
#任务bind=True代表self写，不写代表没有self参数  retry_backoff：循环三次
from celery_tasks.yuntongxun.ccp_sms import CCP


@celery_app.task(bind=True,name="send_sms_code",retry_backoff=3)
def send_sms_code(self,mobile,sms_code):
    '''
    发送短信 尝试发送三次都失败，就抛出去
    :param self:
    :param mobile:
    :param sms_code:
    :return:
    '''
    try:
        result=CCP().send_template_sms(mobile,[sms_code,5],1)
    except Exception as e:

        raise self.retry(exec=1,max_retries=3)

    if result!=0:
        raise self.retry(exex=Exception("发送短信失败"),max_retries=3)
    return result
